package com.example.eddie.test.Util;

import android.util.Log;

import com.example.eddie.test.PoJo.TeacherClassInfo;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class JsoupHtmlUtil {

    public String[][] jsoup(String html) {
        Document document = Jsoup.parse(html);
        Elements k = document.select("td");
        List<String> list = new ArrayList<>();

        for (int i = 0; i < k.size(); i++) {
            Element element = k.get(i);
            String width = element.attr("width");
            String text = element.text();

            if (width.equals("13%") && !text.contains("星期")) {
                list.add(element.text());
                Log.i("xx",text);
            }
        }

        int line = list.size()/7;
        String[][] table = new String[4][7];
        int def = 0;
        for(int x = 0;x<line;x++){
            for(int y = 0;y<table[x].length;y++){
                table[x][y] =list.get(def);
                def+=1;
            }
        }

        return table;
    }

    public void sort(List list){
        Collections.sort(list,new Comparator(){
            @Override
            public int compare(Object o1, Object o2) {
                TeacherClassInfo classInfo1=(TeacherClassInfo) o1;
                TeacherClassInfo classInfo2=(TeacherClassInfo) o2;
                if(classInfo1.getId()>classInfo2.getId()){
                    return 1;
                }else if(classInfo1.getId()==classInfo2.getId()){
                    return 0;
                }else{
                    return -1;
                }
            }
        });
    }

}
